/*
 * Copyright (C) 2013 Daniel Treffenstädt <daniel@treffenstaedt.de>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

#include "OCube.h"

O_START_NAMESPACE

Cube::Cube()
{
	m_x			= 0;
	m_y			= 0;
	m_z			= 0;
	m_water		= false;
	m_faces[0]	= new Face(4, Face::Position::Left);
	m_faces[1]	= new Face(4, Face::Position::Right);
	m_faces[2]	= new Face(4, Face::Position::Front);
	m_faces[3]	= new Face(4, Face::Position::Back);
	m_faces[4]	= new Face(4, Face::Position::Top);
	m_faces[5]	= new Face(4, Face::Position::Bottom);
}

Cube::Cube(short x, short y, short z, bool water)
{
	m_x			= x;
	m_y			= y;
	m_z			= z;
	m_water		= water;
	m_faces[0]	= new Face(4, Face::Position::Left);
	m_faces[1]	= new Face(4, Face::Position::Right);
	m_faces[2]	= new Face(4, Face::Position::Front);
	m_faces[3]	= new Face(4, Face::Position::Back);
	m_faces[4]	= new Face(4, Face::Position::Top);
	m_faces[5]	= new Face(4, Face::Position::Bottom);
}

Cube::~Cube()
{
	for (int i = 0; i < 6; i++)
	{
		delete m_faces[i];
	}
}

short Cube::x()
{
	return m_x;
}

short Cube::y()
{
	return m_y;
}

short Cube::z()
{
	return m_z;
}

void Cube::setX(short x)
{
	m_x		= x;
}

void Cube::setY(short y)
{
	m_y		= y;
}

void Cube::setZ(short z)
{
	m_z		= z;
}

bool Cube::isWater()
{
	return m_water;
}

void Cube::setWater(bool state)
{
	m_water		= state;
}

QList<Face*> Cube::getVisible()
{
	QList<Face*> list;

	if (m_faces[0]->visible())
	{
		list.append(m_faces[0]);
	}
	if (m_faces[1]->visible())
	{
		list.append(m_faces[1]);
	}
	if (m_faces[4]->visible())
	{
		list.append(m_faces[4]);
	}
	if (m_faces[5]->visible())
	{
		list.append(m_faces[5]);
	}
	if (m_faces[2]->visible())
	{
		list.append(m_faces[2]);
	}
	if (m_faces[3]->visible())
	{
		list.append(m_faces[3]);
	}

	return list;
}

Face* Cube::getFace(Face::Position p)
{
	return m_faces[(int) p];
}

void Cube::setFace(Face *f)
{
	m_faces[(int) f->position()]	= f;
}

O_END_NAMESPACE
